package simpledb;

import java.util.Objects;

/**
 * LockState
 * 锁状态类
 * 包含一个锁的Perm(读锁还是写锁)和事务ID
 */
public class LockState {
    private Permissions perm;
    private TransactionId tid;

    public LockState(Permissions perm, TransactionId tid) {
        this.perm = perm;
        this.tid = tid;
    }

    public Permissions getPerm() {
        return perm;
    }

    public TransactionId getTid() {
        return tid;
    }

    public void setPerm(Permissions perm) {
        this.perm = perm;
    }

    public void setTid(TransactionId tid) {
        this.tid = tid;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        LockState lockState = (LockState) o;
        return perm.equals(lockState.perm) && tid.equals(lockState.tid);
    }

    @Override
    public int hashCode() {
        return Objects.hash(perm, tid);
    }
}
